package chapter02

object Test22_List3 {
  def main(args: Array[String]): Unit = {
    val strings = {
      scala.io.Source.fromFile("2020phonelocation.txt").getLines()
    }
    val strings1 = for (i <- strings) yield i
    val list = strings1.toList
    //接收输入
    val phoneNumber = scala.io.StdIn.readLine()
    if(phoneNumber.length!=11){
      println("输入电话号码格式有误")
    }else{
      for(i<-list){
        if(i.contains(phoneNumber.substring(0,7))){
          println(i)
        }
      }
      list.foreach(e=>{if(e.contains(phoneNumber.substring(0,7))) println(e)})
      println(list.filter(_.contains(phoneNumber.substring(0,7))).head)
    }
  }
}
